import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/employee',
    name: 'user',
    meta: { title: '用户管理', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'employee',
        name: 'employee',
        component: () => import('@/views/employee/index'),
        meta: { title: '员工管理', icon: 'el-icon-grape' }
      },
      {
        path: 'taste',
        name: 'taste',
        component: () => import('@/views/supplier/index'),
        meta: { title: '供应商管理', icon: 'el-icon-ice-cream-round' }
      }
    ]
  },
  {
    path: '/finance',
    component: Layout,
    // redirect: '/user/employee',
    name: 'finance',
    meta: { title: '财务管理', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'bill',
        name: 'bill',
        component: () => import('@/views/finance/bill'),
        meta: { title: '出入库台账', icon: 'el-icon-grape' }
      },
      {
        path: 'plan',
        name: 'plan',
        component: () => import('@/views/finance/plan'),
        meta: { title: '计划结算', icon: 'el-icon-ice-cream-round' }
      },
      {
        path: 'yearBill',
        name: 'yearBill',
        component: () => import('@/views/finance/yearBill'),
        meta: { title: '年度台账', icon: 'el-icon-ice-cream-round' }
      }
    ]
  },
  {
    path: '/statistics',
    component: Layout,
    // redirect: '/user/employee',
    name: 'statistics',
    meta: { title: '统计报表', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'carRecord',
        name: 'carRecord',
        component: () => import('@/views/statistics/carRecord'),
        meta: { title: '出车统计', icon: 'el-icon-grape' }
      },
      {
        path: 'electricityRecord',
        name: 'electricityRecord',
        component: () => import('@/views/statistics/electricityRecord'),
        meta: { title: '变电统计', icon: 'el-icon-ice-cream-round' }
      },
      {
        path: 'wireRecord',
        name: 'wireRecord',
        component: () => import('@/views/statistics/wireRecord'),
        meta: { title: '导线统计', icon: 'el-icon-ice-cream-round' }
      },
      {
        path: 'newRecord',
        name: 'newRecord',
        component: () => import('@/views/statistics/newRecord'),
        meta: { title: '新品统计', icon: 'el-icon-grape' }
      },
      {
        path: 'cableRecord',
        name: 'cableRecord',
        component: () => import('@/views/statistics/cableRecord'),
        meta: { title: '电缆统计', icon: 'el-icon-ice-cream-round' }
      },
      {
        path: 'materialRecord',
        name: 'materialRecord',
        component: () => import('@/views/statistics/materialRecord'),
        meta: { title: '物料出入统计', icon: 'el-icon-ice-cream-round' }
      },
      {
        path: 'person',
        name: 'person',
        component: () => import('@/views/statistics/personRecord'),
        meta: { title: '人员任务统计', icon: 'el-icon-ice-cream-round' }
      },

    ]
  },
  {
    path: '/doctor',
    component: Layout,
    redirect: '/doctor/department',
    name: 'doctor',
    meta: { title: '医生相关信息维护', icon: 'el-icon-tableware' },
    children: [
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/banner/index'),
        meta: { title: '科室管理', icon: 'el-icon-picture' }
      },
      {
        path: 'con',
        name: 'con',
        component: () => import('@/views/banner/index'),
        meta: { title: '诊室管理', icon: 'el-icon-picture' }
      }
    ]
  },
  {
    path: '/mediacal',
    component: Layout,
    redirect: '/mediacal/category',
    name: 'system',
    meta: { title: '系统管理', icon: 'el-icon-setting' },
    children: [
      {
        path: '/admin',
        name: 'admin',
        component: () => import('@/views/banner/index'),
        meta: { title: '管理员管理', icon: 'el-icon-user' }
      },
      {
        path: '/role',
        name: 'role',
        component: () => import('@/views/banner/index'),
        meta: { title: '角色管理', icon: 'el-icon-user-solid' }
      },
      {
        path: '/menu',
        name: 'menu',
        component: () => import('@/views/banner/index'),
        meta: { title: '权限管理', icon: 'el-icon-document-copy' }
      }
    ]
  },
  {
    path: '/warehouse',
    component: Layout,
    redirect: '/warehouse/warehouse',
    name: 'warehouse',
    meta: { title: '仓库管理', icon: 'el-icon-coffee-cup' },
    children: [
      {
        path: 'warehouse',
        name: 'warehouse',
        component: () => import('@/views/warehouse/warehouse'),
        meta: { title: '仓库管理', icon: 'el-icon-grape' }
      }
    ]
  },
  {
    path: '/material',
    component: Layout,
    redirect: '/mediacal/material',
    name: 'material',
    meta: { title: '库存管理', icon: 'el-icon-setting' },
    children: [
      {
        path: '/material',
        name: 'material',
        component: () => import('@/views/material/material'),
        meta: { title: '物料管理', icon: 'el-icon-document-copy' }
      },
      {
        path: '/transferrecord',
        name: 'transferrecord',
        component: () => import('@/views/material/transferrecord'),
        meta: { title: '转移记录', icon: 'el-icon-document-copy' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
